package com.longge;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class LargeGroupPositions {

    public List<List<Integer>> largeGroupPositions(String s) {
        ArrayList<List<Integer>> res = new ArrayList<>();
        char[] chars = s.toCharArray();
        int count = 1, left = 0, right = 0;
        char cur = ' ';
        for (int i = 0; i < chars.length; i++) {
            if (cur == chars[i]) {
                count++;
                right = i;
            } else if (cur != chars[i]) {
                if (count >= 3) {
                    res.add(Arrays.asList(left, right));
                }
                cur = chars[i];
                count = 1;
                left = i;
            }
        }
        if (count>=3){
            res.add(Arrays.asList(left, right));
        }
        return res;
    }
}
